package com.whsxt.controller;

import com.whsxt.domain.Area;
import com.whsxt.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-03-18 16:40
 * @Description:
 */
@RestController
@RequestMapping("/admin/area")
@Api(tags = "地址管理接口")
public class AreaController {


    @Autowired
    private AreaService areaService;


    @GetMapping("/list")
    @ApiOperation(value = "全查询地址")
    public ResponseEntity<List<Area>> findAreaList() {
        List<Area> list = areaService.list();
        return ResponseEntity.ok(list);
    }


    @PostMapping
    @ApiOperation(value = "新增地址")
    public ResponseEntity<Void> addArea(@RequestBody Area area) {
        areaService.save(area);
        return ResponseEntity.ok().build();
    }


    @GetMapping("listByPid")
    @ApiOperation("根据父id查询地址集合")
//    @PreAuthorize("hasAuthority('admin:area:info')")
    public ResponseEntity<List<Area>> listByPid(Long pid) {
        List<Area> areas = areaService.findAreaByPid(pid);
        return ResponseEntity.ok(areas);
    }


}
